home *** CD-ROM | disk | FTP | other *** search
- Path: news.luc.edu!user
- From: VArase@varase.it.luc.edu (Verne Arase)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: Sun, 10 Mar 1996 22:04:07 -0600
- Organization: LUMC
- Message-ID: <AD690257966810CEF@mcdialb10.it.luc.edu>
- References: <4htonk$350@news.hklink.net>
- NNTP-Posting-Host: 147.126.240.126
-
- In article <4htonk$350@news.hklink.net>,
- alex@station.net (Alex Chu) wrote:
-
- >typedef struct item {
- > int val;
- > struct item *next;
- >} ITEM, *PITEM;
- >
- >main()
- >{
- > PITEM head, current;
- > head=(PITEM) malloc(sizeof(ITEM));
- > ^^^^^^^
- > head->val=1;
- >}
- >
- >I want to know why need to use the type casting PITEM in front of the
- >malloc ? Please help!
-
- If the header was designed for ANSI C, it's probably redundant. An ANSI C
- header should define malloc as returning a void *.
-
- If it's for a pre-ANSI C, malloc is probably defined as returning a char *.
- Therefore, the cast is required to coerce the returned address into head.
-
- ---
- The above are my own opinions, and not those of my employer.
-